﻿<Window x:Class="Viewport3DRayTracer.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:raywpf="clr-namespace:RayTracer.WPF;assembly=RayTracer"
    xmlns:koda3D="clr-namespace:Koda.WPF.Media3D;assembly=Koda.WPF"
    Title="Window1" Height="500" Width="1200" Background="#efffef"
    Loaded="Window_Loaded">
  <Window.Resources>
    <MaterialGroup x:Key="WireMaterial" >
      <DiffuseMaterial Brush="Blue" />
      
      <SpecularMaterial Brush="White" SpecularPower="500"/>
    
    </MaterialGroup>
    
    <koda3D:CircleWire x:Key="StandardWireShape" Radius="5" Slices="3"/>

    <koda3D:WireMeshBuilder x:Key="WireMeshBuilder">
      <koda3D:WireFigure3D WireShape="{StaticResource StandardWireShape}" Approximation="10"
                         StartPoint="0,0,0"
                         Segments="
                           C0,0,2      10,0,4    10,10,6
                           C10,10,6    10,20,8   0,20,10
                           C0,20,10     -10,20,12  -10,10,14
                           C-10,10,14   -10,0,16   0,0,18
                           C0,0,18      10,0,20    10,10,22
                           C10,10,22   10,20,24  0,20,26
                           C0,20,26    -10,20,28 -10,10,30
                           C-10,10,30  -10,0,32  0,0,40
                           "/>
      <!--
                           L11,2,12
                           L0,4,13
                           L0,6,0
                           L14,8,0
                           L15,10,16
                           L0,12,17
                           L0,14,0
                           L18,16,0
                           L19,18,20
                           L0,20,21
                           L0,22,0
                           L22,24,0
                           L23,26,24
                           L0.0,28,25
                           "/>
      -->
    </koda3D:WireMeshBuilder>
    
    <Model3DGroup x:Key="RunnerBasketModel">
      <Model3DGroup></Model3DGroup>
        <GeometryModel3D Geometry="{Binding Source={StaticResource WireMeshBuilder}, Path=MeshGeometry}"
                         Material="{StaticResource WireMaterial}">
        <GeometryModel3D.Transform>
          <TranslateTransform3D OffsetX="15.1"/>
        </GeometryModel3D.Transform>
      </GeometryModel3D>
    </Model3DGroup>
  </Window.Resources>
  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="200"/>
      <ColumnDefinition/>
      <ColumnDefinition/>
    </Grid.ColumnDefinitions>

    <StackPanel Background="#ffefef">
      <Button Content="Ray Trace Scene" Click="RayTraceScene_ButtonClick"/>
      <StackPanel Orientation="Horizontal">
        <Label>Ray Tracer Time: </Label>
        <TextBox x:Name="RayTracerTime" Width="105"/>
      </StackPanel>
      <StackPanel Orientation="Horizontal">
        <Label>Preprocess Time:</Label>
        <TextBox x:Name="PreprocessTime" Width="105"/>
      </StackPanel>
      <StackPanel Orientation="Horizontal">
        <Label>Number of Triangles:</Label>
        <TextBox x:Name="NumTrianglesText" Width="80"/>
      </StackPanel>
    </StackPanel>

    <Image x:Name="MainImage"           
           RenderTransformOrigin="0.5,0.5"
           Grid.Column="1"
           MouseDown="MainImage_MouseDown">
      <Image.RenderTransform>
        <ScaleTransform ScaleY="-1"/>
      </Image.RenderTransform>
    </Image>

    <DockPanel Background="#ffffff" Grid.Column="2">
      <ScrollBar Name="VerticalScrollBar" DockPanel.Dock="Left" Minimum="-180" Maximum="180" />
      <ScrollBar Name="HorizontalScrollBar" DockPanel.Dock="Bottom" Orientation="Horizontal" Minimum="-180" Maximum="180"/>
      <Viewport3D Name="ViewPort" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <Viewport3D.Resources>
          <MeshGeometry3D x:Key="CubeMesh"
                  Positions="0 1 1, 1 1 1,
                             0 0 1, 1 0 1,
                             1 1 0, 0 1 0,
                             1 0 0, 0 0 0,
                             0 1 0, 0 1 1,
                             0 0 0, 0 0 1,
                             1 1 1, 1 1 0,
                             1 0 1, 1 0 0,
                             0 1 0, 1 1 0,
                             0 1 1, 1 1 1,
                             1 0 0, 0 0 0,
                             1 0 1, 0 0 1"
                  TriangleIndices=" 0  2  1,  1  2  3,
                                    4  6  5,  5  6  7,
                                    8 10  9,  9 10 11,
                                   12 14 13, 13 14 15,
                                   16 18 17, 17 18 19,
                                   20 22 21, 21 22 23"
                  TextureCoordinates="0 0, 1 0, 0 1, 1 1,
                                      0 0, 1 0, 0 1, 1 1,
                                      0 0, 1 0, 0 1, 1 1,
                                      0 0, 1 0, 0 1, 1 1,
                                      0 0, 1 0, 0 1, 1 1,
                                      0 0, 1 0, 0 1, 1 1" />

          <ImageBrush x:Key="KoalaImageBrush" ImageSource="C:\Users\Public\Pictures\Sample Pictures\Koala.jpg"
                      ViewboxUnits="Absolute" Stretch="Fill">
          </ImageBrush>
        </Viewport3D.Resources>
        <!-- Simple Camera -->
        <Viewport3D.Camera>
          <PerspectiveCamera x:Name="ViewportCamera" Position="0,0,110" UpDirection="0,1,0" 
                LookDirection="0,0,-1" FieldOfView="45" FarPlaneDistance="1000" >
          </PerspectiveCamera>
        </Viewport3D.Camera>

        <!-- Room Lights -->
        <ModelVisual3D x:Name="Lights_MV3D">
          <ModelVisual3D.Content>
            <Model3DGroup>
              <PointLight Color="White" Position="80,80,-10" />    
              <AmbientLight Color="#444" />
            </Model3DGroup>
          </ModelVisual3D.Content>
        </ModelVisual3D>

        <!-- The Products Model3D -->
        <ModelVisual3D >
          <ModelVisual3D.Content>
            <Model3DGroup x:Name="Group3D">
                          
              
              <GeometryModel3D Geometry="{StaticResource CubeMesh}">
                <GeometryModel3D.Material>
                  <MaterialGroup>
                    <DiffuseMaterial Brush="#FF666666"/>
                    <SpecularMaterial Brush="White" SpecularPower="400"/>
                  </MaterialGroup>
                </GeometryModel3D.Material>

                <GeometryModel3D.Transform>
                  <Transform3DGroup>
                    <TranslateTransform3D OffsetY="-10.0"/>
                    <ScaleTransform3D CenterX="0.3" CenterY="0.5" CenterZ="0.3" ScaleX="500.0" ScaleZ="500.0"/>
                  </Transform3DGroup>
                </GeometryModel3D.Transform>
              </GeometryModel3D>
              
              <Model3DGroup>
                <!--
                <StaticResource ResourceKey="RunnerBasketModel"/>

                -->
                <GeometryModel3D Geometry="{StaticResource CubeMesh}">
                  <GeometryModel3D.Material>
                    <MaterialGroup>
                      <DiffuseMaterial Brush="{StaticResource KoalaImageBrush}"/>
                    </MaterialGroup>
                  </GeometryModel3D.Material>
                  <GeometryModel3D.Transform>
                    <Transform3DGroup>
                      <ScaleTransform3D CenterX="0.5" CenterY="0.5" CenterZ="0.5" ScaleX="5" ScaleY="15" ScaleZ="15"/>
                      <TranslateTransform3D OffsetX="10" />
                    </Transform3DGroup>
                  </GeometryModel3D.Transform>
                </GeometryModel3D>
                <GeometryModel3D Geometry="{StaticResource CubeMesh}">
                  <GeometryModel3D.Material>
                    <MaterialGroup>
                      <DiffuseMaterial Brush="Green"/>
                    </MaterialGroup>
                  </GeometryModel3D.Material>
                  <GeometryModel3D.Transform>
                    <Transform3DGroup>
                      <ScaleTransform3D CenterX="0.5" CenterY="0.5" CenterZ="0.5" ScaleX="5" ScaleY="15" ScaleZ="15"/>
                      <TranslateTransform3D OffsetX="-10" />
                    </Transform3DGroup>
                  </GeometryModel3D.Transform>
                </GeometryModel3D>
                
                <Model3DGroup.Transform>
                  <Transform3DGroup>
                    <RotateTransform3D x:Name="ModelYRotation" CenterX="0.5" CenterY="0.5" CenterZ="0.5">
                      <RotateTransform3D.Rotation>
                        <AxisAngleRotation3D Axis="0,1,0" Angle="{Binding ElementName=HorizontalScrollBar, Path=Value}"/>
                      </RotateTransform3D.Rotation>
                    </RotateTransform3D>
                    <RotateTransform3D x:Name="ModelXRotation" CenterX="0.5" CenterY="0.5" CenterZ="0.5">
                      <RotateTransform3D.Rotation>
                        <AxisAngleRotation3D Axis="1,0,0" Angle="{Binding ElementName=VerticalScrollBar, Path=Value}" />
                      </RotateTransform3D.Rotation>
                    </RotateTransform3D>
                    <!--<ScaleTransform3D CenterX="0.5" CenterY="0.5" CenterZ="0.5" ScaleX="15" ScaleY="15" ScaleZ="15"/>
                    <TranslateTransform3D />-->
                  </Transform3DGroup>
                </Model3DGroup.Transform>
              </Model3DGroup>
            </Model3DGroup>
          </ModelVisual3D.Content>
        </ModelVisual3D>
      </Viewport3D>
    </DockPanel>
  </Grid>
</Window>
